import axios from "axios";

// 配置跨域携带 Cookie
axios.defaults.withCredentials = true;

const service = axios.create({
    baseURL: '/api',
    timeout: 10000,
});

// 配置请求变量
service.interceptors.request.use((config) => {
    return config;
}, (error) => {
    return error;
});

// 配置回复变量
service.interceptors.response.use((response) => {
    if (response.status === 200) {
        return response;
    } else {
        return Promise.reject(new Error(response.statusText || 'Error'));
    }
}, (error) => {
    return Promise.reject(error);
});

export interface IResponse {
    code: number;
    msg: string;
    data: object;
}

export default service;